home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 52 / Amiga Format AFCD52 (Issue 136, May 2000).iso / -serious- / programming / other / pmdev / c / demos / layout.c < prev    next >
C/C++ Source or Header  |  2000-02-28  |  4KB  |  200 lines

  1. /*
  2.  *
  3.  * $VER: Layout.c 1.0 (16.07.99)
  4.  *
  5.  * Popup Menu example program
  6.  *
  7.  * ©1996-1998 Henrik Isaksson
  8.  * All Rights Reserved.
  9.  *
  10.  */
  11.  
  12. #include <intuition/intuition.h>
  13. #include <exec/memory.h>
  14.  
  15. #include <proto/intuition.h>
  16. #include <proto/exec.h>
  17.  
  18. #include <clib/alib_protos.h>
  19.  
  20. #include <string.h>
  21. #include <stdio.h>
  22. #include <stdlib.h>
  23.  
  24. #include <libraries/pm.h>
  25. #include <proto/pm.h>
  26.  
  27. struct IntuitionBase    *IntuitionBase;
  28. struct GfxBase        *GfxBase;
  29. struct PopupMenuBase    *PopupMenuBase;
  30.  
  31. struct Window *w;
  32.  
  33. struct PopupMenu *MakeTestMenu(void);
  34.  
  35. void PrintMenu(struct PopupMenu *pm, int level);
  36.  
  37. void main()
  38. {
  39.     struct IntuiMessage *im,imsg;
  40.     struct PopupMenu *p;
  41.     BOOL r=TRUE;
  42.  
  43.     PopupMenuBase=(struct PopupMenuBase *)OpenLibrary(POPUPMENU_NAME,POPUPMENU_VERSION);            // Open the library
  44.     if(PopupMenuBase) {
  45.         IntuitionBase=(struct IntuitionBase *)PopupMenuBase->pmb_IntuitionBase;    // We let popupmenu.library open the libraries we need
  46.         GfxBase=(struct GfxBase *)PopupMenuBase->pmb_GfxBase;            // They remain valid until the library is closed!
  47.  
  48.         p=MakeTestMenu(); // Declared at the end of this file.
  49.  
  50.         if(p) {
  51.             w=OpenWindowTags(NULL,    WA_IDCMP,    IDCMP_CLOSEWINDOW|IDCMP_MOUSEBUTTONS|IDCMP_VANILLAKEY,    // Open a little window
  52.                     WA_RMBTrap,    TRUE,
  53.                     WA_DragBar,    TRUE,
  54.                     WA_Width,    150,
  55.                     WA_Height,    100,
  56.                     WA_Left,    0,
  57.                     WA_Top,        100,
  58.                     WA_Title,    "Layout",
  59.                     WA_CloseGadget,    TRUE,
  60.                     TAG_DONE);
  61.             if(w) {
  62.                 while(r) {
  63.                     WaitPort(w->UserPort);                        // Wait for a message
  64.                     while((im=(struct IntuiMessage *)GetMsg(w->UserPort))) {    // Get the message
  65.                         CopyMem(im,&imsg,sizeof(struct IntuiMessage));        // Copy the contents of it
  66.                         ReplyMsg((struct Message *)im);                // Reply the message
  67.  
  68.                         if(imsg.Class==IDCMP_MOUSEBUTTONS) {
  69.                             PM_OpenPopupMenu(w,
  70.                                 PM_Menu,        p,
  71.                                 TAG_DONE);
  72.                         }
  73.                         if(imsg.Class==IDCMP_CLOSEWINDOW) r=FALSE;        // See if the user wants to quit
  74.                     }
  75.                 }
  76.                 CloseWindow(w);
  77.             } else printf("Window error!\n");
  78.             PM_FreePopupMenu(p);
  79.         } else printf("Menu error!\n");
  80.         CloseLibrary((struct Library *)PopupMenuBase);
  81.     }
  82. }
  83.  
  84. struct PopupMenu *MakeTestMenu()
  85. {
  86.     struct PopupMenu *p;
  87.  
  88.     p=PMMenu("Group Layout"),
  89.  
  90.         PMHoriz,
  91.             PMMembers,
  92.  
  93.                 PMItem("Left"), PM_Center, TRUE, End,
  94.  
  95.                 PMVert,
  96.                     PMMembers,
  97.                         PMItem("Item 1"), PM_Center, TRUE, End,
  98.                         PMItem("Item 2"), PM_Center, TRUE, End,
  99.                         PMItem("Item 3"), PM_Center, TRUE, End,
  100.                         PMItem("Item 4"), PM_Center, TRUE, End,
  101.                         PMItem("Item 5"), PM_Center, TRUE, End,
  102.                         PMItem("Item 6"), PM_Center, TRUE, End,
  103.                     End,
  104.                 End,
  105.  
  106.                 PMItem("Right"), PM_Center, TRUE, End,
  107.  
  108.             End,
  109.         End,
  110.  
  111.         PMBar,    End,
  112.  
  113.         PMVert,
  114.             PMMembers,
  115.  
  116.                 PMHoriz,
  117.                     PMMembers,
  118.                         PMColBox(1), End,
  119.                         PMColBox(2), End,
  120.                         PMColBox(3), End,
  121.                         PMColBox(4), End,
  122.                         PMColBox(5), End,
  123.                         PMColBox(6), End,
  124.                         PMColBox(7), End,
  125.                         PMColBox(8), End,
  126.                         PMColBox(9), End,
  127.                         PMColBox(0), End,
  128.                     End,
  129.                 End,
  130.  
  131.                 PMHoriz,
  132.                     PMMembers,
  133.                         PMColBox(11), End,
  134.                         PMColBox(12), End,
  135.                         PMColBox(13), End,
  136.                         PMColBox(14), End,
  137.                         PMColBox(15), End,
  138.                         PMColBox(16), End,
  139.                         PMColBox(17), End,
  140.                         PMColBox(18), End,
  141.                         PMColBox(19), End,
  142.                         PMColBox(10), End,
  143.                     End,
  144.                 End,
  145.  
  146.                 PMHoriz,
  147.                     PMMembers,
  148.                         PMColBox(21), End,
  149.                         PMColBox(22), End,
  150.                         PMColBox(23), End,
  151.                         PMColBox(24), End,
  152.                         PMColBox(25), End,
  153.                         PMColBox(26), End,
  154.                         PMColBox(27), End,
  155.                         PMColBox(28), End,
  156.                         PMColBox(29), End,
  157.                         PMColBox(20), End,
  158.                     End,
  159.                 End,
  160.  
  161.                 PMHoriz,
  162.                     PMMembers,
  163.                         PMColBox(31), End,
  164.                         PMColBox(32), End,
  165.                         PMColBox(33), End,
  166.                         PMColBox(34), End,
  167.                         PMColBox(35), End,
  168.                         PMColBox(36), End,
  169.                         PMColBox(37), End,
  170.                         PMColBox(38), End,
  171.                         PMColBox(39), End,
  172.                         PMColBox(30), End,
  173.                     End,
  174.                 End,
  175.  
  176.                 PMHoriz,
  177.                     PMMembers,
  178.                         PMColBox(41), End,
  179.                         PMColBox(42), End,
  180.                         PMColBox(43), End,
  181.                         PMColBox(44), End,
  182.                         PMColBox(45), End,
  183.                         PMColBox(46), End,
  184.                         PMColBox(47), End,
  185.                         PMColBox(48), End,
  186.                         PMColBox(49), End,
  187.                         PMColBox(40), End,
  188.                     End,
  189.                 End,
  190.  
  191.             End,
  192.         End,
  193.  
  194.         PMBar,    End,
  195.         PMItem("Quit"), End,
  196.     End;
  197.     
  198.     return p;
  199. }
  200.